package com.yxw.live_vod_backend_boot.vo;

import com.yxw.live_vod_backend_boot.entity.YxCsDeptEntity;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

@Data
@Accessors(chain = true)
public class DeptTreeItemVO implements Serializable {

    /**
     * 数据id，Element UI控件要求名为value
     */
    private Long value;

    /**
     * 名称，Element UI控件要求名为label
     */
    private String label;

    /**
     * 子级列表，Element UI控件要求名为children
     */
    private List<DeptTreeItemVO> children;

    public DeptTreeItemVO(YxCsDeptEntity dept) {
        this.value = dept.getDeptId();
        this.label = dept.getDeptName();
        this.children = dept.getChildren().stream().map(DeptTreeItemVO::new).collect(Collectors.toList());
    }
}
